#include "except.h"
#include <assert.h>
#include <stdlib.h>

#define T Except_T

except_Frame *__ex_frame = NULL;

void
except_raise(const T *ex, const char *file, int line) {
	assert(ex != NULL);
	except_Frame *frame = __ex_frame; // 当前处理异常的处理程序，是记录抛出异常的载体。
	if (frame == NULL) {
		if (file) {
			fprintf(stderr, "no frame info to raise, msg:%s file:%s line:%d\n", ex?ex->msg:"*", file, line);
		} else {
			fprintf(stderr, "no frame info to raise, msg:%s\n", ex?ex->msg:"*");
		}
		fprintf(stderr, "aborting now");
		abort();
	}

	__ex_frame = frame->prev;

	frame->except = ex;
	frame->file = file;
	frame->line = line;

	longjmp(frame->env, except_RAISED);
}
